import streamlit as st


class Model:
    def __init__(self):
        self.data = "pile of data"


class View:
    def __init__(self):
        if "click" not in st.session_state:
            st.session_state.click = False

        if "result" not in st.session_state:
            st.session_state.result = "Press the button to calculate"

        st.write(st.session_state)
        self.drawUI()
        self.session_state = st.session_state

    def drawUI(self):
        runButton = st.button(
            "Run", on_click=self.onButtonClickFunction, kwargs={"key": "click"}
        )
        st.text(st.session_state.result)

    def onButtonClickFunction(self, key):
        st.session_state[key] = True

    def display_message(self, message):
        st.write(message)

    def set_result(self, value):
        st.write("result: {}".format(value))
        st.session_state.result = value


class Controller:
    def __init__(self, model, view):
        self.model = model
        self.view = view

        if self.view.session_state.click:
            self.view.display_message("message from controller")
            # st.session_state.result = "123"
            # self.view.session_state.result = "456"
            self.view.set_result("789")


def main():
    st.title("Button MVC Demo")

    model = Model()
    view = View()
    controller = Controller(model, view)


if __name__ == "__main__":
    main()